// https://learn.microsoft.com/en-us/typography/opentype/spec/vhea

use super::*;

#[derive(Debug, Clone)]
pub struct Table {
	pub version: Version16Dot16,        // Version number of the vertical header table; 0x00010000 for version 1.0
	pub ascent: FWORD,                  // Distance in font design units from the centerline to the previous line’s descent.
	pub descent: FWORD,                 // Distance in font design units from the centerline to the next line’s ascent.
	pub line_gap: FWORD,                // Reserved; set to 0
	pub advance_height_max: UFWORD, // The maximum advance height measurement in font design units found in the font. This value must be consistent with the entries in the vertical metrics table.
	pub min_top_side_bearing: FWORD, // The minimum top sidebearing measurement found in the font, in font design units. This value must be consistent with the entries in the vertical metrics table.
	pub min_bottom_side_bearing: FWORD, // The minimum bottom sidebearing measurement found in the font, in font design units. This value must be consistent with the entries in the vertical metrics table.
	pub y_max_extent: FWORD,            // Defined as yMaxExtent = max(tsb + (yMax - yMin)).
	pub caret_slope_rise: i16, // The value of the caretSlopeRise field divided by the value of the caretSlopeRun Field determines the slope of the caret. A value of 0 for the rise and a value of 1 for the run specifies a horizontal caret. A value of 1 for the rise and a value of 0 for the run specifies a vertical caret. Intermediate values are desirable for fonts whose glyphs are oblique or italic. For a vertical font, a horizontal caret is best.
	pub caret_slope_run: i16,  // See the caretSlopeRise field. Value=1 for nonslanted vertical fonts.
	pub caret_offset: i16, // The amount by which the highlight on a slanted glyph needs to be shifted away from the glyph in order to produce the best appearance. Set value equal to 0 for nonslanted fonts.
	pub reserved0: i16,    // Set to 0.
	pub reserved1: i16,    // Set to 0.
	pub reserved2: i16,    // Set to 0.
	pub reserved3: i16,    // Set to 0.
	pub metric_data_format: i16, // Set to 0.
	pub num_metrics: u16,  // Number of advance heights in the vertical metrics table.
}
impl Table {
	pub fn parse(data: &[u8]) -> Option<Self> {
		let mut s = Stream::new(data);
		let this = Self {
			version: s.read()?,
			ascent: s.read()?,
			descent: s.read()?,
			line_gap: s.read()?,
			advance_height_max: s.read()?,
			min_top_side_bearing: s.read()?,
			min_bottom_side_bearing: s.read()?,
			y_max_extent: s.read()?,
			caret_slope_rise: s.read()?,
			caret_slope_run: s.read()?,
			caret_offset: s.read()?,
			reserved0: s.read()?,
			reserved1: s.read()?,
			reserved2: s.read()?,
			reserved3: s.read()?,
			metric_data_format: s.read()?,
			num_metrics: s.read()?,
		};
		Some(this)
	}
}
